package com.example.ll_video.activity;

import android.view.View;

import com.example.ll_video.adapter.PayMoneyAdapter;
import com.example.ll_video.adapter.PayTypeAdapter;
import com.example.ll_video.bean.PayMoney;
import com.example.ll_video.bean.PayType;
import com.example.ll_video.bean.ResultData;
import com.example.ll_video.bean.VideoData;
import com.example.ll_video.constant.Constant;
import com.example.ll_video.utils.HttpUtils;
import com.example.ll_video.utils.JsonUtil;
import com.example.ll_video.R;
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton;

import java.util.List;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

public class PayActivity extends BaseActivity {
    @BindView(R.id.rv_money)
    RecyclerView rvMoney;
    @BindView(R.id.rv_pay_type)
    RecyclerView rvPayType;
    @BindView(R.id.btn_pay)
    QMUIRoundButton btnPay;
    private PayMoneyAdapter payMoneyAdapter;
    private PayTypeAdapter payTypeAdapter;
    private PayType nowPayType;
    private PayMoney nowPayMoney;
    @Override
    public void onCreate() {
        contentView(R.layout.activity_pay_ll);
        ButterKnife.bind(this);

        setTitle("Vip充值");
        showBackImage(v -> finish());

        GridLayoutManager gridLayoutManager1 = new GridLayoutManager(context,3);
        rvMoney.setLayoutManager(gridLayoutManager1);
        GridLayoutManager gridLayoutManager2 = new GridLayoutManager(context,2);
        rvPayType.setLayoutManager(gridLayoutManager2);
        getDataList();
        getMoneyList();
    }

    private void getDataList() {
        HttpUtils.get(Constant.PAY_LIST, new HttpUtils.HttpCallBack() {
            @Override
            public void onSuccess(ResultData resultData) {
                if (resultData.getCode() == 1) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            List<PayType> payTypes = JsonUtil.jsonToList(resultData.getData(),PayType.class);
                            payTypeAdapter = new PayTypeAdapter(context,payTypes);
                            rvPayType.setAdapter(payTypeAdapter);
                            payTypeAdapter.setItemClickListener(new PayTypeAdapter.ItemClickListener() {
                                @Override
                                public void onItemClick(int position, PayType payType) {
                                    payTypeAdapter.refresh(position);
                                    nowPayType = payType;
                                }
                            });
                        }
                    });

                }
            }

            @Override
            public void onFail(String error) {
            }
        });
    }
    private void getMoneyList() {
        HttpUtils.get(Constant.VIP_LIST, new HttpUtils.HttpCallBack() {
            @Override
            public void onSuccess(ResultData resultData) {
                if (resultData.getCode() == 1) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            List<PayMoney> payMonies = JsonUtil.jsonToList(resultData.getData(),PayMoney.class);
                            payMoneyAdapter = new PayMoneyAdapter(context,payMonies);
                            rvMoney.setAdapter(payMoneyAdapter);
                            payMoneyAdapter.setItemClickListener(new PayMoneyAdapter.ItemClickListener() {
                                @Override
                                public void onItemClick(int position, PayMoney payMoney) {
                                    payMoneyAdapter.refresh(position);
                                    nowPayMoney = payMoney;
                                }
                            });
                        }
                    });

                }
            }

            @Override
            public void onFail(String error) {
            }
        });
    }
}
